1 using UnityEngine;
2 using
System.Collections;
3
4 public
class SoundManager : MonoBehaviour
5 {
6     
public AudioClip button, pause, shot, dead, pickup, p_harm, p_dead;
7     
public AudioClip boss;
8
9     AudioSource[] audSources;
//0 - player, 1 - enemy, 2 - UI, 3 - music
10
11     
void Awake ()
12     {
13         audSources = GetComponents<AudioSource>();
14     }
15
16     
void Start()
17     {
18         
if (!SystemScr.mute)
19             PlayMusic(
true);
20     }
21
22     
public void PlaySoundsPlayer(int soundNumber)
23     {
24         
if (SystemScr.mute)
25             
return;
26
27         
if (soundNumber == 0)
28             audSources[
0].clip = shot;
29         
else if (soundNumber == 1)
30             audSources[
0].clip = p_harm;
31         
else if (soundNumber == 2)
32             audSources[
0].clip = p_dead;
33         
else if(soundNumber == 3)
34             audSources[
0].clip = pickup;
35
36         audSources[
0].Play();
37     }
38
39     
public void PlaySoundsEnemy()
40     {
41         
if (SystemScr.mute)
42             
return;
43         audSources[
1].clip = dead;
44         audSources[
1].Play();
45     }
46
47     
public void PlaySoundsUI(bool buttonSound)
48     {
49         
if (SystemScr.mute)
50             
return;
51         
if (buttonSound)
52             audSources[
2].clip = button;
53         
else
54             audSources[
2].clip = pause;
55
56         audSources[
2].Play();
57     }
58
59     
public void BossMusicOn()
60     {
61         audSources[
3].clip = boss;
62         audSources[
3].volume = 0.8f;
63         audSources[
3].Play();
64     }
65
66     
public void PlayMusic(bool on)
67     {
68         
if (on)
69             audSources[
3].Play();
70         
else
71             audSources[
3].Stop();
72     }
73 }


AudioSource[] audSources;0 - player, 1 - enemy, 2 - UI, 3 - music




Trò chơi game bắn súng đơn giản trong UNITY Engine 23.600 lượt xem

Gõ tìm kiếm nhanh...